package com.wng.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Description;

/**
 * rabbitmq 配置类
 */
@Configuration
public class RabbitMQConfig {

    @Value("${queueName}")
    private String queueName;
    @Value("${exchangeName}")
    private String exchangeName;

    @Bean("bootExchange")
    public Exchange bootExchange() {
        return ExchangeBuilder.topicExchange(exchangeName).build();
    }

    @Bean("bootQueue")
    public Queue bootQueue() {
        return QueueBuilder.durable(queueName).build();
    }

    @Bean
    public Binding bootBinding(@Qualifier("bootQueue") Queue queue, @Qualifier("bootExchange")Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("#.error").noargs();
    }
}
